---
title: Avoid Flutter Imports
description: The avoid_flutter_imports bloc lint rule.
---

import { Badge } from '@astrojs/starlight/components';
import EnableRuleSnippet from '~/components/lint-rules/EnableRuleSnippet.astro';
import BadSnippet from '~/components/lint-rules/avoid_flutter_imports/BadSnippet.mdx';
import GoodSnippet from '~/components/lint-rules/avoid_flutter_imports/GoodSnippet.astro';

<div class="badges">
	<Badge text="new" />
	<Badge text="dart" variant="note" />
	<Badge text="recommended" variant="success" />
</div>

Avoid introducing dependencies on Flutter within business logic components
(`Bloc` or `Cubit` instances).

## Rationale

Layering an application is a key part of building a maintainable codebase and
helps developers iterate quickly and with confidence. Each layer should have a
single responsibility and be able to function and tested in isolation. This
allows you to contain changes to specific layers, minimizing the impact on the
entire application.

As a result, business logic components should generally manage feature state and
be decoupled from the UI layer. Events should flow into business logic
components from the UI layer and state should flow out of the business logic
layer into the UI layer.

Keeping business logic components decoupled from Flutter provides the ability to
reuse business logic across multiple platforms/frameworks (e.g. Flutter,
AngularDart, Jaspr, etc.).

## Examples

**DO NOT** import Flutter within your business logic components.

**BAD**:

<BadSnippet />

**GOOD**:

<GoodSnippet />

## Enable

To enable the `avoid_flutter_imports` rule, add it to your
`analysis_options.yaml` under `bloc` > `rules`:

<EnableRuleSnippet name="avoid_flutter_imports" />
